package practice3.persistence;

import java.util.Iterator;
import java.util.List;

import practice3.persistence.dao.MyDao;



public class MyServiceImpl implements MyService{
	
	private MyDao myDao;

	public void setMyDao(MyDao myDao) {
		this.myDao = myDao;
	}

	/**
	 * <p>Method ：doSomething
	 * <p>Description : 功能描述
	 *
	 * @throws Exception 
	 * @see practice2.ioc.MyService#doSomething()
	 */
	@Override
	public void getUsers() throws Exception {
		 System.out.println("当前用户：");
		 List<User> users = myDao.doQuery();
		 for (Iterator<User> iterator = users.iterator(); iterator.hasNext();) {
			User user = (User) iterator.next();
			System.out.println(user.getId()+" -- "+user.getName());
		}
		
	}

	@Override
	public void addUser(User u) throws Exception {
		System.out.println("增加用户："+u.getName());
		myDao.addUser(u);
	}

	/**
	 * <p>Method ：addUserEx
	 * <p>Description : 
	 *
	 * @param u
	 * @throws Exception 
	 * @see practice3.persistence.MyService#addUserEx(practice3.persistence.User)
	 */
	@Override
	public void addUserEx(User u) throws Exception {
		myDao.addUserEx(u);
	}

	/**
	 * <p>Method ：getUserById
	 * <p>Description : 功能描述
	 *
	 * @param id
	 * @throws Exception 
	 * @see practice3.persistence.MyService#getUserById(java.lang.String)
	 */
	@Override
	public User getUserById(String id) throws Exception {
		return myDao.getUserById(id);
	}
}
